<!-- 入口页面 -->
<template>
	<view class="entrance">
		<view class="logo">
			<image src="../../static/images/logo.png" mode=""></image>
			<p>中源慧云</p>
		</view>
		<view class="scan">
			<view class="btn">
				<u-button @click="handleScan" type="primary" color="#f0851b" shape="circle" text="扫一扫"></u-button>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				islogin:''
			};
		},
		methods: {
			handleScan() {
				console.log('扫一扫');
				uni.scanCode({
					// onlyFromCamera: true,
					sourceType: ['album'], // 从相册选择
					count: 1, // 默认9，设置为1表示一次只能选择一张图片
					scanType: ['qrCode'],
					success: (res) => {
						// 返回选定照片的本地文件路径列表
						console.log('扫描成功');
						// res.result 包含了扫描得到的结果
						console.log(res.result);
						const scanResult = res.result; // 假设您想在Vue的数据中保存结果
						uni.getStorage({
							key:'isLogin',
							 success: function(res) {
							    console.log('读取成功:', res.data);
								this.islogin=res.data;
							  },
							  fail: function(res) {
							    console.log('读取失败');
							  }
						})
						if(this.islogin!==''){
							uni.navigateTo({
								 url: `/pages/index/index?scanResult=${scanResult}`
							})
						}else{
							uni.navigateTo({
								 url: `/pages/login/login?scanResult=${scanResult}`
							})
						}
						

					},
					fail: (err) => {
						console.log('取消扫描', err);
					}

				})
			},
		},
	}
</script>

<style lang="scss" scoped>
	.entrance {

		// logo图标
		.logo {
			height: 40vh;
			display: flex;
			flex-direction: column;
			justify-content: center;
			align-items: center;

			image {
				margin: 30rpx 0;
				width: 150rpx;
				height: 150rpx;
			}

			p {
				font-size: 60rpx;
				color: #f0851b;
			}
		}

		.scan {

			height: 60vh;
			position: relative;

			// top: 100rpx;
			// display: flex;
			// justify-content: center;
			.btn {
				width: 75%;
				position: absolute;
				// top: 200rpx;
				// top: 0;
				bottom: 200rpx;
				right: 0;
				left: 0;
				// margin: auto;
				margin: auto;
			}
		}

	}
</style>